using UnityEngine;
using System.Collections;

public class ObjectSelector : MonoBehaviour {
	
	private GameObject selected;

	void Update () {
		GameObject sphere = GameObject.Find("Sphere");
		Vector3 t = new Vector3();
		t.z = sphere.transform.position.z;
		t.x = sphere.transform.position.x;
		t.y = 0;
		this.transform.position = t;
	}
	
	//Check which object to open
	void OnCollisionEnter(Collision col) {
		col.gameObject.transform.Find("KuutioImage").renderer.material.color = Color.cyan;
		selected = col.gameObject;
	}
	
	void OnCollisionExit(Collision col) {
		col.gameObject.transform.Find("KuutioImage").renderer.material.color = Color.white;
		selected = null;		
	}

	//Open selected object in default application (or in this case in firefox)
	public void PickUp() {
		if (selected != null) {
			KinectMenuItem i = selected.GetComponent<KinectMenuItem>();
			
			// Works in Windows and firefox, refactor for multiplatform
			System.Diagnostics.Process.Start("firefox.exe", i.path.url);
		}
	}
}